package com.swf.seed.algorithms.tree;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: Forest <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason:森林，用于存放树. <br/>
 * date: 2015-1-23 上午10:28:46 <br/>
 *
 * @author shenwf10476
 * @version 
 * @since JDK 1.6
 */
public class Forest {
	private Map<Character,Node> treeMap;
	
	public Forest() {
		treeMap = new HashMap<Character, Node>();
	}
	public Map<Character, Node> getTreeMap() {
		return treeMap;
	}
	
	public void setTreeMap(Map<Character, Node> treeMap) {
		this.treeMap = treeMap;
	}
	
	public void addOrUpdateTree(Node newTree){
		Character key = newTree.getKey();
		
		if (treeMap.containsKey(key)){
			Node node = treeMap.get(key);
			node.merge(newTree);
			treeMap.put(key, node);
		}else{
			treeMap.put(newTree.getKey(),newTree);
		}
	}
	
	public boolean contains(Node tree){
		return treeMap.containsKey(tree.getKey());
	}
	
	public boolean contains(char c){
		return treeMap.containsKey(c);
	}
	
}
